package com.kb.erp.controller;

import cn.hutool.json.JSON;
import cn.hutool.json.JSONObject;
import cn.hutool.json.JSONUtil;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.kb.erp.common.ApiResponse;
import com.kb.erp.domain.PersonGradeInfo;
import com.kb.erp.entity.AttCardData;
import com.kb.erp.entity.HrEntity;
import com.kb.erp.entity.PayAccount;
import com.kb.erp.entity.PerDepartInfo;
import com.kb.erp.service.HrService;
import com.xxl.job.core.handler.annotation.XxlJob;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;
import java.util.Objects;

/**
 * hr系统
 */
@RequestMapping("/hr")
@RestController
public class HrController {

    @Resource
    private HrService hrService;

    @PostMapping("/queryResignInfo")
    public List<HrEntity> queryResignInfo(@RequestBody HrEntity hrEntity){
        return hrService.queryResignInfo(hrEntity);
    }
    /**
     * 删除或更新员工日志的任务处理方法
     *
     * 该方法通过GET请求触发，主要用于定期清理或更新不再需要的员工日志信息
     * 它被标记为一个XXL作业，以便于分布式任务调度
     */
    @GetMapping("/delUpdateEmployeeLogs")
    @XxlJob("delUpdateEmployeeLogs")
    public void queryResignInfo(){
         hrService.delUpdateEmployeeLogs();
    }

    /**
     * 查询打卡记录
     */
    @PostMapping("/queryAttCardData")
    public ApiResponse queryAttCardData(@RequestBody Map map){
        if (Objects.isNull(map.get("startTime"))){
            return ApiResponse.error("开始时间必填");
        }
        List<AttCardData> cardDataList = hrService.queryAttCardData(map);
        return ApiResponse.successCount(cardDataList,cardDataList.size());
    }
    /**
     *费控
     * @param page
     * @param pageSize
     * @return
     */
    @PostMapping("/queryBankCard")
    public Page<PayAccount> queryBankCard(@RequestParam int page, @RequestParam int pageSize) {
        return hrService.queryBankCard(page, pageSize);
    }
    /**
     *费控-查询部门数据
     * @param page
     * @param pageSize
     * @return
     */
    @PostMapping("/queryDepartInfo")
    public Page<PerDepartInfo> queryDepartInfo(@RequestParam int page, @RequestParam int pageSize) {
        return hrService.queryDepartInfo(page, pageSize);
    }

    /**
     *费控-人员职等信息

     * @return
     */
    @PostMapping("/personGradeInfo")
    public JSON personGradeInfo() {
        return (JSONUtil.parse(hrService.personGradeInfo()));
    }
}
